//
//  AppDelegate.m
//  07_UITabBarController
//
//  Created by dllo on 16/7/22.
//  Copyright © 2016年 yh. All rights reserved.
//

#import "AppDelegate.h"
#import "ViewController.h"
#import "FirstViewController.h"
#import "SecViewController.h"

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    [self.window makeKeyAndVisible];
    self.window.backgroundColor = [UIColor whiteColor];
//    self.window.rootViewController = [[[UINavigationController alloc] initWithRootViewController:[[ViewController alloc] init]];
//    ViewController *vc = [[ViewController alloc] init];
//    UINavigationController *navigation = [[UINavigationController alloc] initWithRootViewController:vc];
    
    // UITabBarController 标签视图控制器
    // 主要管理没有层级关系的视图控制器
    // 1. viewControllers 数组中包含所有被管理的视图控制器 可以通过setter方法去赋值
    // 2. 通过一个数组创建完成后 如果数组中的控制器没有设置tabBarItem那么tabBar是空的 如果设置了tabBarItem (可以根据标题和图片去创建tabBarItem) tabBarItem是vc的属性 由vc来调用
    // 设置tabBarItem(在数组中放的是谁就设置谁的tabBarItem)
    
#if 0
    // 全局设置 (appearance 也使用UINavigation)
    [[UITabBar appearance] setTintColor:[UIColor cyanColor]];
    [[UITabBar appearance] setBarTintColor:[UIColor grayColor]];
    
    UITabBarController *tabBar = [[UITabBarController alloc] init];

    ViewController *vc1 = [[ViewController alloc] init];
    UINavigationController *navigation1 = [[UINavigationController alloc] initWithRootViewController:vc1];
    [[UINavigationBar appearance] setBarTintColor:[UIColor grayColor]];
    // 1. self.title 会修改两个内容: navigationItem.title和tabBarItem.title
    // 2. self.navigationItem.title 只会修改navigationBar上的title
    vc1.title = @"测试";
//    vc1.navigationItem.title = @"测试";
    
    // 修改标题颜色
    [[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor whiteColor]}];

    vc1.view.backgroundColor = [UIColor redColor];
    // 自己对tabBar的设置 文字和图片 (还有一种自己创建的方式可以增添选中图片)
    vc1.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"新闻'" image:nil tag:1000];
    // 系统的tabBar设置
    vc1.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem: UITabBarSystemItemFavorites tag:1000];
    // 设置角标
    vc1.tabBarItem.badgeValue = @"100";
    ViewController *vc2 = [[ViewController alloc] init];
    vc2.view.backgroundColor = [UIColor greenColor];
    vc2.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"视频" image:nil tag:1001];
    
    ViewController *vc3 = [[ViewController alloc] init];
    vc3.view.backgroundColor = [UIColor redColor];
    vc3.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"电影" image:nil tag:1002];
    ViewController *vc4 = [[ViewController alloc] init];
    vc4.view.backgroundColor = [UIColor redColor];
    vc4.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"直播" image:nil tag:1003];
    // [tabBar setViewControllers:@[vc1, vc2, vc3, vc4]];
    // 如果数组中元素大于5 tabBar会显示"..."
    // tabBar的高度是49
    tabBar.viewControllers = @[navigation1, vc2, vc3, vc4];
    // 给tabBar修改颜色
//    tabBar.tabBar.barTintColor = [UIColor cyanColor];
    // 设置tabBar中元素的颜色
//    tabBar.tabBar.tintColor = [UIColor blueColor];
    // 设置tabBar是否透明
    tabBar.tabBar.translucent = YES;
    self.window.rootViewController = tabBar;
#endif
    
    
    UITabBarController *tabBar = [[UITabBarController alloc] init];
    
    ViewController *vc1 = [[ViewController alloc] init];
    UINavigationController *navigation1 = [[UINavigationController alloc] initWithRootViewController:vc1];
    
    FirstViewController *vc2 = [[FirstViewController alloc] init];
    UINavigationController *navigation2 = [[UINavigationController alloc] initWithRootViewController:vc2];
    
    SecViewController *vc3 = [[SecViewController alloc] init];
    UINavigationController *navigation3 = [[UINavigationController alloc] initWithRootViewController:vc3];
    
    tabBar.viewControllers = @[navigation1, navigation2, navigation3];
    tabBar.tabBar.translucent = NO;
    self.window.rootViewController = tabBar;
    
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
